package com.andy.wan.android.mvp.ui.fragment

import androidx.recyclerview.widget.RecyclerView
import com.andy.ui.base.BaseListFragment
import com.andy.ui.base.SimpleWebActivity
import com.andy.ui.widget.PageStateView
import com.andy.wan.android.R
import com.andy.wan.android.mvp.api.WanAndroidApi
import com.andy.wan.android.mvp.bean.BaseResponse
import com.andy.wan.android.mvp.bean.FeedArticleData
import com.andy.wan.android.mvp.bean.FeedArticleListData
import com.andy.wan.android.mvp.net.RetrofitUtil
import com.andy.wan.android.mvp.ui.adapter.FeedArticleAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.scwang.smartrefresh.layout.SmartRefreshLayout
import io.reactivex.Observable
import kotlinx.android.synthetic.main.fragment_simple_list.*

/**
 *@Author: luofan
 *@CreateDate: 2020/12/17 14:51
 *@Description: 收藏列表
 */
class LikeFillFragment : BaseListFragment<BaseResponse<FeedArticleListData>, FeedArticleData>() {

    override fun getObservable(): Observable<BaseResponse<FeedArticleListData>> {
        return RetrofitUtil.getInstance().create(WanAndroidApi::class.java).getLikeFillData(pageNum)
    }

    override fun getLayoutId(): Int {
        return R.layout.fragment_simple_list
    }

    override fun getRecyclerDataFromResult(response: BaseResponse<FeedArticleListData>): MutableList<FeedArticleData> {
        return response.data.datas
    }

    override fun getRecyclerView(): RecyclerView {
        return recycler_view
    }

    override fun getRefreshLayout(): SmartRefreshLayout? {
        return smart_refresh
    }

    override fun getPageStateView(): PageStateView {
        return page_stat_view
    }

    override fun getAdapter(): BaseQuickAdapter<FeedArticleData, BaseViewHolder> {
        val itemAdapter = FeedArticleAdapter()
        itemAdapter.onItemClickListener = BaseQuickAdapter.OnItemClickListener { adapter, view, position ->
            val bean = itemAdapter.getItem(position)
            if (bean != null) {
                SimpleWebActivity.startMe(context, bean.link, bean.title)
            }
        }
        return itemAdapter
    }
}